package com.huika.dealontop.control.myinfo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.huika.dealontop.R;
import com.huika.dealontop.control.base.BaseAda;
import com.huika.dealontop.support.domain.MyOrderItemBean;
import com.huika.dealontop.utils.ImageLoaderHelper;
import com.huika.dealontop.utils.UIUtils;
import com.huika.huikalib.utils.StringUtils;

import java.text.DecimalFormat;

/**
 * 分类附近子节点适配器
 */
public class MyOrderListAdapter extends BaseAda<MyOrderItemBean> {
    private Context context;

    public MyOrderListAdapter(Context context) {
        super(context);
        this.context = context;
    }


    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vh = null;
        if (view == null) {
            view = mInflater.inflate(R.layout.item_orderitem_detail, viewGroup, false);
           vh = new ViewHolder(view);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        MyOrderItemBean locallistbean = getItem(i);

        if (StringUtils.isEmpty(locallistbean.getPicUrl())) {
            vh.iv_picture.setImageResource(R.mipmap.morenpic);
        } else {
            ImageLoaderHelper.displayImage(locallistbean.getPicUrl(), vh.iv_picture);
        }
        vh.tv_name.setText(locallistbean.getProductName());
        vh.tv_price.setText(Math.round(Float.parseFloat(locallistbean.getCouponPrice())) + "");
        vh.mOrderlistNumber.setText(locallistbean.getCopies()+ UIUtils.getResources().getString(R.string.myorderlist_dish));

        // * orderStatus: 1.待付款 2.已付款 3.已使用 4.已退款 5.已过期6.已取消
//        filterlist.add(new FilterBeanTwo(getString(R.string.myorder_list_filter_nopay), false, 1));
//        filterlist.add(new FilterBeanTwo(getString(R.string.myorder_list_filter_nouse), false, 2));
//        filterlist.add(new FilterBeanTwo(getString(R.string.myorder_list_has_use), false, 3));
//        filterlist.add(new FilterBeanTwo(getString(R.string.myorder_list_filter_backprice), false, 4));
//        filterlist.add(new FilterBeanTwo(getString(R.string.myorder_list_has_expired), false, 5));
//        filterlist.add(new FilterBeanTwo(getString(R.string.myorder_list_filter_alreadycancle), false, 6));
//        filterlist.add(new FilterBeanTwo(getString(R.string.myorder_list_filter_readycomment), false, 7));
        String textTemp = "";
        switch(locallistbean.getOrderStatus()){
            case "1":
                textTemp = UIUtils.getString(R.string.myorder_list_filter_nopay);
                break;
            case "2":
                textTemp = UIUtils.getString(R.string.myorder_list_filter_nouse);
                break;
            case "3":
                textTemp = UIUtils.getString(R.string.myorder_list_has_use);
                break;
            case "4":
                textTemp = UIUtils.getString(R.string.myorder_list_filter_backprice);
                break;
            case "5":
                textTemp = UIUtils.getString(R.string.myorder_list_has_expired);
                break;
            case "6":
                textTemp = UIUtils.getString(R.string.myorder_list_filter_alreadycancle);
                break;
            case "7":
                textTemp = UIUtils.getString(R.string.myorder_list_filter_readycomment);
                break;
        }
        vh.mOrderlistState.setText(textTemp);
        //vh.tv_zhekounum.setText(Math.round(locallistbean.getDiscount()) + "%");
        /*vh.tv_juli.setText(nearbyLocallistbean.getDiscount());*/
        //vh.rb_pingfen.setRating(Math.round(locallistbean.getEvaluateScore()));
        //vh.tv_pingfennum.setText(Math.round(locallistbean.getEvaluateScore()) + "");
        return view;
    }

    private int formatPrice(float price) {
        try {
            DecimalFormat df = new DecimalFormat("0.0");
            return Integer.parseInt(df.format(price));
        } catch (Throwable t) {
            return 0;
        }
    }

    class ViewHolder {
        public ImageView iv_picture;
        public TextView tv_name, tv_price,mOrderlistNumber,mOrderlistState;

        public ViewHolder(View view) {
            mOrderlistNumber = (TextView) view.findViewById(R.id.myorderlist_number);
            iv_picture = (ImageView) view.findViewById(R.id.project_iv_icon);
            tv_name = (TextView) view.findViewById(R.id.project_tv_name);
            tv_price = (TextView) view.findViewById(R.id.project_tv_price);
            mOrderlistState = (TextView) view.findViewById(R.id.myorderlist_state);
        }
    }
}
